<?php if(!defined('IN_CORE')) exit('Access Denied'); ?>
<!DOCTYPE html>
<html lang="en">
  <head>
    <meta charset="utf-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1">
    <meta name="description" content="">
    <meta name="author" content="">

    <title>代码同步系统</title>

    <!-- Bootstrap core CSS -->
    <link href="/static/bootstrap/css/bootstrap.min.css" rel="stylesheet">

    <!-- HTML5 shim and Respond.js for IE8 support of HTML5 elements and media queries --> 
    <!--[if lt IE 9]>
      <script src="http://cdn.bootcss.com/html5shiv/3.7.0/html5shiv.js" type="text/javascript"></script>
      <script src="http://cdn.bootcss.com/respond.js/1.4.2/respond.min.js" type="text/javascript"></script>
    <![endif]-->
    <meta name="viewport" content="width=device-width, initial-scale=1">
    <link rel="stylesheet" href="/static/css/zTreeStyle/metro.css">
  </head>

  <body>

    <!-- Static navbar -->
    <nav class="navbar navbar-default navbar-static-top" role="navigation">
      <div class="container">
        <div class="navbar-header">
          <a class="navbar-brand" href="#">代码同步系统</a>
        </div>
        <div id="navbar" class="navbar-collapse collapse">
          <ul class="nav navbar-nav navbar-right">
            <li>
              <form class="navbar-form navbar-left">
                <button data-toggle="modal" data-target="#add_subject" type="button" class="btn btn-success">添加项目</button>
              </form>
            </li>
            <li>
              <form class="navbar-form navbar-left">
                <button data-toggle="modal" data-target="#mdf_subject" type="button" class="btn btn-info">切换项目</button>
              </form>
            </li>
          </ul>
        </div><!--/.nav-collapse -->
      </div>
    </nav>

    <div class="container">
      <div class="panel panel-default">
        <div class="panel-heading">
          <span class="glyphicon glyphicon-home" aria-hidden="true"></span>&nbsp;
          <?php echo $subject['dir'];?> - <?php echo $subject['name'];?>
        </div>
        <div class="panel-body">
          <div class="btn-group" role="group" aria-label="...">
          <button type="button" key="<?php echo $subject['key'];?>" simulate="1" class=" rsync_code btn btn-success">模拟同步</button>
            <button type="button" key="<?php echo $subject['key'];?>" simulate="0" class="rsync_code btn btn-info">正式同步</button>
            <button type="button" id="clear_select" class="btn btn-warning">清除选择</button>
          </div>

          <br /><br />

          <textarea class="form-control" rows="6" id="select_node"><?php echo $sync_files;?></textarea>

          <br />

          <div class="well">
            <ul id="tree" class="ztree" style="width:560px; overflow:auto;"></ul>
          </div>
        </div>
      </div>  
    </div> 
    <!-- /container -->

    <!-- Modal -->
    <div class="modal" id="add_subject" tabindex="-1" role="dialog" aria-labelledby="myModalLabel" aria-hidden="true">
      <div class="modal-dialog">
        <div class="modal-content">
          <div class="modal-header">
            <button type="button" class="close" data-dismiss="modal"><span aria-hidden="true">&times;</span><span class="sr-only">Close</span></button>
            <h4 class="modal-title" id="myModalLabel">添加项目</h4>
          </div>
          <div class="modal-body">
            <form class="form-horizontal" role="form">
              <div class="form-group">
                <label for="inputEmail3" class="col-sm-2 control-label">项目名称</label>
                <div class="col-sm-10">
                  <input type="text" class="form-control" name="subject_name" id="subject_name" placeholder="项目名称">
                </div>
              </div>
              <div class="form-group">
                <label for="inputPassword3" class="col-sm-2 control-label">项目目录</label>
                <div class="col-sm-10">
                  <input type="text" class="form-control" id="subject_dir" name="subject_dir" placeholder="项目目录">
                </div>
              </div>
              <div class="form-group">
                <label for="inputPassword3" class="col-sm-2 control-label">服务器同步模块</label>
                <div class="col-sm-10">
                  <input type="text" class="form-control" id="subject_module" name="subject_module" placeholder="服务器同步模块">
                </div>
              </div>
            </form>
          </div>
          <div class="modal-footer">
            <div class="error" style="color:red;float:left;"></div>
            <button type="button" class="btn btn-default" data-dismiss="modal">取消</button>
            <button type="button" id="submit_suject" class="btn btn-primary">保存数据</button>
          </div>
        </div>
      </div>
    </div>
    <!-- /Modal -->

    <!-- Modal -->
    <div class="modal" id="mdf_subject" tabindex="-1" role="dialog" aria-labelledby="myModalLabel" aria-hidden="true">
      <div class="modal-dialog">
        <div class="modal-content">
          <div class="modal-header">
            <button type="button" class="close" data-dismiss="modal"><span aria-hidden="true">&times;</span><span class="sr-only">Close</span></button>
            <h4 class="modal-title" id="myModalLabel">切换项目</h4>
          </div>
          <div class="modal-body">
              <ul class="list-group">
                <?php if(is_array($subjects)) foreach($subjects as $key => $v) { ?>                  <?php if($v['key'] != $subject['key']) { ?>
                    <li class="list-group-item">
                        <a href="/index/index/<?php echo $v['key'];?>/"><?php echo $v['name'];?> - <?php echo $v['dir'];?></a>
                        <a class="subject_remove" key="<?php echo $v['key'];?>" title="移除">
                          <span class="glyphicon glyphicon glyphicon-remove pull-right"></span>
                        </a>
                    </li>
                  <?php } ?>
                <?php } ?>
              </ul>
          </div>
          <div class="modal-footer">
            <div class="error" style="color:red;float:left;"></div>
            <button type="button" class="btn btn-default" data-dismiss="modal">取消</button>
          </div>
        </div>
      </div>
    </div>
    <!-- /Modal -->

    <!-- Modal -->
    <div class="modal" id="rsync_result" tabindex="-1" role="dialog" aria-labelledby="myModalLabel1" aria-hidden="true">
      <div class="modal-dialog">
        <div class="modal-content">
          <div class="modal-header">
            <button type="button" class="close" data-dismiss="modal"><span aria-hidden="true">&times;</span><span class="sr-only">Close</span></button>
            <h4 class="modal-title" id="myModalLabel1"><a simulate="" subject="" href="javascript:;" class="rsync_repeat" title="重复同步"> &nbsp;<span class="glyphicon glyphicon-repeat"></span></a>  &nbsp;&nbsp;&nbsp;同步结果(<span class="rsync_type"></span>)</h4>
          </div>
          <div class="modal-body">
            <p class="show_result">
              数据同步中 ......
            </p>
          </div>
          <div class="modal-footer">
            <div class="error" style="color:red;float:left;"></div>
            <button type="button" class="btn btn-primary rsync_repeat" real_sync="1" simulate="" subject="" href="javascript:;">正式同步</button>
            <button type="button" class="btn btn-default" data-dismiss="modal">取消</button>
          </div>
        </div>
      </div>
    </div>
    <!-- /Modal -->


    <script src="/static/js/jquery-1.11.1.min.js" type="text/javascript"></script>
    <script src="/static/js/jquery.ztree.all-3.5.min.js" type="text/javascript"></script>
    <script src="/static/bootstrap/js/bootstrap.min.js" type="text/javascript"></script>
    <script src="/static/bootstrap/js/bootstrap-dropdown.js" type="text/javascript"></script>
    <script src="/static/js/common.js" type="text/javascript"></script>

    <script type="text/javascript">
      //判断是否有项目
      var has_subject = <?php if($subject) { ?>true<?php } else { ?>false<?php } ?>;
      var dir = "<?php echo $subject['dir'];?>";
      
      $(document).ready(function(){
        common.init(has_subject, dir);
      });
    </script>
  </body>
</html>
